home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / IAC Tools / iacdouble.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-09  |  2.8 KB  |  164 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1993 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4. #include "iacinternal.h"
  5.  
  6.  
  7. #if __option(mc68881) || !__option(native_fp)
  8.  
  9.     #define useSane
  10.     
  11.     #include <sane.h>
  12.     
  13. #else
  14.     
  15.     #undef useSane
  16.     
  17. #endif
  18.  
  19.  
  20. #if __option (double_8)
  21.  
  22.     #error Can't compile this project with the 8 byte doubles option set
  23.     
  24.     /*use short double instead if you need 8 byte IEEE (SANE) doubles*/
  25.     
  26. #endif
  27.  
  28.  
  29.  
  30. Boolean IACpushdoubleparam (double val, OSType keyword) {
  31.     
  32.     register OSErr ec;
  33.     extended value;
  34.     
  35.     #ifdef useSane    
  36.         x96tox80 (&val, &value); /*convert from double to extended*/        
  37.     #else    
  38.         value = val; /*no conversion needed, just copy it*/        
  39.     #endif
  40.         
  41.     ec = AEPutParamPtr (
  42.         
  43.         IACglobals.event, (AEKeyword) keyword, typeExtended, 
  44.         
  45.         (Ptr) &value, sizeof (value));
  46.         
  47.     IACglobals.errorcode = ec;
  48.     
  49.     return (ec == noErr);
  50.     } /*IACpushdoubleparam*/
  51.  
  52.  
  53. Boolean IACreturndouble (double x) {
  54.     
  55.     register OSErr ec;
  56.     extended value;
  57.     
  58.     #ifdef useSane
  59.         x96tox80 (&x, &value);
  60.     #else
  61.         value = x;
  62.     #endif
  63.         
  64.     ec = AEPutParamPtr (
  65.         
  66.         IACglobals.reply, keyDirectObject, typeExtended, (Ptr)&value, 
  67.         
  68.         (Size) sizeof (value));
  69.         
  70.     IACglobals.errorcode = ec;
  71.     
  72.     return (ec == noErr);
  73.     } /*IACreturndouble*/
  74.  
  75.  
  76. Boolean IACgetdoubleparam (OSType keyword, double *val) {
  77.     
  78.     register OSErr ec;
  79.     DescType actualtype;
  80.     Size actualsize;
  81.     extended value;
  82.     
  83.     ec = AEGetParamPtr (
  84.         
  85.         IACglobals.event, (AEKeyword) keyword, typeExtended, 
  86.         
  87.         &actualtype, (Ptr) &value, sizeof (value), &actualsize);
  88.     
  89.     IACglobals.errorcode = ec;
  90.     
  91.     if (ec != noErr) {
  92.         
  93.         IACparamerror (ec, "\pdouble", keyword);
  94.         
  95.         return (false);
  96.         }
  97.     
  98.     IACglobals.nextparamoptional = false; /*must be reset for each param*/
  99.     
  100.     #ifdef useSane
  101.         x80tox96 (&value, val);
  102.     #else
  103.         *val = value;
  104.     #endif
  105.  
  106.     return (true);
  107.     } /*IACgetdoubleparam*/
  108.     
  109.     
  110. Boolean IACgetdoubleitem (AEDescList *list, long n, double *val) {
  111.     
  112.     register OSErr ec;
  113.     extended value;
  114.     DescType key;
  115.     DescType typeCode;
  116.     Size actualSize;
  117.  
  118.     if ((*list).descriptorType == typeAERecord) {
  119.         
  120.         ec = AEGetKeyPtr (list, n, typeExtended, &typeCode, (Ptr) &value, sizeof (value), &actualSize);
  121.             
  122.         if (ec != errAEDescNotFound)
  123.             goto done;
  124.         }
  125.     
  126.     ec = AEGetNthPtr (list, n, typeExtended, &key, &typeCode, (Ptr) &value, sizeof (value), &actualSize);
  127.     
  128.     done:
  129.     
  130.     IACglobals.errorcode = ec;
  131.     
  132.     #ifdef useSane
  133.         x80tox96 (&value, val);
  134.     #else
  135.         *val = value;
  136.     #endif
  137.     
  138.     return (ec == noErr);
  139.     } /*IACgetdoubleitem*/
  140.  
  141.  
  142. Boolean IACpushdoubleitem (AEDescList *list, double val, long n) {
  143.     
  144.     register OSErr ec;
  145.     extended    value;
  146.  
  147.     #ifdef useSane
  148.         x96tox80 (&val, &value); 
  149.     #else
  150.         value = val;
  151.     #endif
  152.     
  153.     if ((*list).descriptorType == typeAERecord)
  154.         ec = AEPutKeyPtr (list, n, typeExtended, (Ptr)&value, sizeof (value));
  155.     else
  156.         ec = AEPutPtr (list, n, typeExtended, (Ptr)&value, sizeof (value));
  157.     
  158.     IACglobals.errorcode = ec;
  159.     
  160.     return (ec == noErr);
  161.     } /*IACpushdoubleitem*/
  162.  
  163.  
  164.